<?php
declare(strict_types=1);

namespace LowCode\Naive;

use LowCode\Naive;
use LowCode\Node;
use LowCode\Support\JsExp;
use LowCode\Traits\Props\HasExtra;
use LowCode\Traits\Props\HasSubTitle;
use LowCode\Traits\Props\HasTitle;
use LowCode\Traits\Slots\HasSlotAvatar;
use LowCode\Traits\Slots\HasSlotExtra;
use LowCode\Traits\Slots\HasSlotFooter;
use LowCode\Traits\Slots\HasSlotHeader;
use LowCode\Traits\Slots\HasSlotSubTitle;
use LowCode\Traits\Slots\HasSlotTitle;

/**
 * PageHeader组件
 * @method static static make(string|JsExp $title, string|JsExp $subtitle = "", mixed $children = null) PageHeader组件
 */
class PageHeader extends Naive
{
    use HasTitle, HasSubTitle, HasExtra;

    use HasSlotHeader, HasSlotTitle, HasSlotFooter, HasSlotExtra, HasSlotSubTitle, HasSlotAvatar;

    /**
     * @param string|JsExp $title
     * @param string|JsExp $subtitle
     * @param mixed|null $children
     */
    public function __construct(string|JsExp $title, string|JsExp $subtitle = "", mixed $children = null)
    {
        parent::__construct();
        $this->title($title)->children($children);
        if ($subtitle){
            $this->subtitle($subtitle);
        }
    }

    /**
     * 启用点击返回事件
     * @param string $event
     * @param string|null $id
     * @param array $modifiers
     * @return $this
     */
    public function onBack(string $event = "()=>{ this.\$router.back() }", string $id = null, array $modifiers = []): static
    {
        return $this->event("back",jsFn($event, $id), $modifiers);
    }

    /**
     * 设置 slot back 内容
     * @param Node $node
     * @return $this
     */
    public function slotBack(Node $node): static
    {
        return $this->addSlot($node,'back');
    }
}
